package com.mycompany.myapp.web.rest.controller;

import com.mycompany.myapp.service.MenuService;
import com.mycompany.myapp.service.dto.MenuDTO;
import com.mycompany.myapp.web.rest.utils.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"后台管理-商品类别管理"})
@RestController
@RequestMapping("/api")
public class MTypeController {
    @Autowired
    private MenuService menuService;

    @ApiOperation("添加商品分类")
    @PostMapping("/mtype/create")
    public ResultObj createTypeInfo(@RequestBody MenuDTO menuDTO) {
        return menuService.createTypeInfo(menuDTO);
    }

    @ApiOperation("查询全部商品类型")
    @GetMapping("/mtype/findTypeByParams")
    private ResultObj findByParams(@RequestParam(value = "pagenum") int pageNum,
                                   @RequestParam(value = "pagesize") int pageSize,
                                   @RequestParam(value = "query") String username) {
        return menuService.findByParams(pageNum, pageSize, username);
    }

    @ApiOperation("删除商品分类")
    @DeleteMapping("/mtype/delete")
    public ResultObj deleteTypeInfo(@RequestParam(value = "id") long id) {
        return menuService.deleteTypeInfo(id);
    }


    @ApiOperation("修改商品分类")
    @PostMapping("/mtype/update")
    public ResultObj updateMenu(@RequestBody MenuDTO menuDTO) {
        return menuService.updateMenu(menuDTO);
    }


}
